<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <style>
        body {
            padding-top: 1.5rem;
        }

        .header {
            width: 93%;
            height: 2.5rem;
            line-height: 2.5rem;
            padding: 0.5rem 0.8rem;
            text-align: center;
            border-bottom: 1px solid rgb(243, 243, 243, 0.5);
            background-color: #fff;
            position: fixed;
            top:1.5rem;
            z-index: 99999
        }

        .header_img{
          width: 6%;
          height: 45%;
          float: left;
          margin-top: 0.5rem;
        }

        .header_img img {
            width: 100%;
            height: 100%;
        }

        .header h3 {
            line-height: 2.5rem;
            margin: 0 auto;
        }

        .math {
            width: 90%;
            height: 100%;
            background-color: rgb(242, 242, 242, 0.5);
            padding: 0.8rem 1rem;
            margin-top: 4rem;
        }

        .math_one {
            width: 100%;
            height: 6rem;
            margin-top: 0.8rem;
            border-radius: 0.5rem;
        }

        .one_img {
            width: 90%;
            height: 6rem;
            margin: 0 auto;
            position: absolute;
            /*padding: 1rem 0.8rem;*/
        }

        .one_img img {
            width: 100%;
            height: 100%;
        }

        .one_text {
            position: relative;
            width: 50%;
            top: 16%;
            z-index: 999;
            margin-left: 1.2rem;
            float: left;
        }

        .one_w {
            position: relative;
            top: 36%;
            right:2.5%;
            width: 24%;
            border-radius: 1rem;
            height: 2rem;
            line-height: 2rem;
            text-align: center;
            background-color: #40cccc;
            color: #fff;
            float: right;
        }
    </style>
</head>

<body>
    <div class="header">
        <div class="header_img" onclick="closewin()">
            <img src="../image/u18.png" alt="">
        </div>
        <h3>我的优惠券</h3>
    </div>
    <div class="math" id="jlist">
      
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.3.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
var userinfo=$api.getStorage('userinfo')
    apiready = function() {

      // 获取个人优惠卷
      get_my()

    };

    function get_my(){
      var html =''
      var obj = $api.byId('jlist');

      api.ajax({
          url: SITE_URL+'user_api/coupon/get_list',
          method: 'post',
          data: {
              values: {
                  user_id: userinfo.id
              }
          }
      },function(ret, err){
          if (ret) {
          //  alert( JSON.stringify( ret ) );
            if(ret.error==200){
              if(ret.data.length>0){
                for (var i = 0; i < ret.data.length; i++) {
                  var dat = ret.data[i]
                  if(dat.type==1){//商铺
                    html +='<div class="math_one" onclick="opend('+dat.shop_id+')">'
                  }else if(dat.type==2){//平台
                    html +='<div class="math_one" onclick="opens()">'
                  }else{//商品
                    html +='<div class="math_one" onclick="openss('+dat.cur_id+')">'
                  }

                  html +='<div class="one_img">'
                  html +='<img src="../image/a19.png" alt="">'
                  html +='</div>'
                  html +='<div class="one_text">'
                  html +='<p style="color:red;font-size:2rem;"><span style="font-size:0.9rem;">￥</span>'+dat.money+'</p>'
                  html +='<p style="color:#ccc;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;">'+dat.name+'</p>'
                  html +='</div>'
                  html +='<div class="one_w">'
                  html +='<p style="font-size:0.9rem">立即使用</p>'
                  html +='</div>'
                  html +='</div>'
                }
                $api.html(obj, html);

              }
            }else{
              msgcode('您还没有优惠卷')
            }

          } else {
            msgcode('请检查网络连接')
              //alert( JSON.stringify( err ) );
          }
      });

    }

    function openss(id) {
      api.openWin({
          name: 'curlist',
          url: './curlist.html',
          pageParam: {
                      id: id
                  }
      });
    }
    function opend(id) {

      api.openWin({
          name: 'brand',
          url: './brand.html',
          pageParam: {
                      id: id
                  }
      });
    }

    function opens() {
      api.openWin({
          name: 'search',
          url: './search.html',
          pageParam: {
                      search_value: ''
                  }
      });
    }
</script>

</html>
